package com.neko.Thread_Learning;

// Thread.sleep(int ms) 模拟【网络延时】：放大【问题的发生性】
public class t10_1_Thread_sleep implements Runnable {
    // 票数
    private int ticketNums = 10;


    @Override
    public void run() {

        while (true) {

            if (ticketNums <= 0) {
                break;
            }

            try {
                // 模拟演示
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


            System.out.println(Thread.currentThread().getName() + "-->拿到了第 " + ticketNums-- + " 张 票");

        }
    }


    public static void main(String[] args) {

        t10_1_Thread_sleep thread = new t10_1_Thread_sleep();

        /**
         * 模拟【多个线程】抢【同一个资源】问题
         * */
        new Thread(thread, "小明").start();
        new Thread(thread, "老师").start();
        new Thread(thread, "黄牛党").start();


    }
}
